<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="6" v-for="i in 4" key="i"></el-col>
      <el-col :span="6" :offset="0" v-for="(item, index) in panels" :key="index">
        <el-card shadow="hover" class="border-0">
          <template #header>
            <div class="flex justify-between"></div>
            <span class="text-sm">{{ item.title }}</span>
            <el-tag :type="item.type" effect="plain">
              {{ item.label }}
            </el-tag>
          </template>
          <span class="text-3xl font-bold text-gray-500">
            {{ item.value }}
          </span>
          <el-divider />
          <div class="flex justify-between text-sm text-gray-500"></div>
          <span>{{ item.subTitie }}</span>
          <span>{{ item.subvalue }}</span>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { getstatisticsl } from '~/api/index.js';

const panels = ref([]);

// 使用更规范的异步获取方式
onMounted(async () => {
  try {
    const res = await getstatisticsl();
    panels.value = res.panels || [];
    console.log(panels.value);
  } catch (error) {
    console.error('获取数据失败', error);
  }
});
</script>